// 记录rid值
var rid;
// 新增按钮
function add() {
    // 初始化新增表单
    addUserRole = [];
    addDepartment = [];
    addProvideOrg = [];
    // console.log(addUserRole);
    document.getElementById("addUserRoleSelected").innerText = "";
    document.getElementById("addDepartmentSelected").innerText = "";
    document.getElementById("addProvideOrgSelected").innerText = "";
    document.getElementById("addRid").value = "";
    
    // 打开修改窗口
    document.getElementById('addBlock').style.display = 'block';
    // 打开遮罩层
    document.getElementById('mask').style.display = 'block';
}

// 提交按钮
function addSubmit() {
    
    var msg = "请确认新增策略内容！";
    if (confirm(msg)==true){
        var addInfo = addUserRole.join("|") + ","
            + addDepartment.join("|") + ","
            + addProvideOrg.toString() + ","
            + document.getElementById("addRid").value;
        console.log(addInfo);
        // 发送请求
        $.ajax({
            url: "http://127.0.0.1:8023/abac/policy/info",
            type: "POST",
            dataType: "JSON",
            contentType: "application/x-www-form-urlencoded",
            // async:false,
            data: {
                pType: "P",
                policy: addInfo
            },
            success: function(res) {
                // location.reload();  //实现页面重新加载
                // 重新获取表格数据
                getData();
                load();
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                alert("添加失败！");
            }
        });
        return true;
    }else{
        // 关闭修改对话框
        document.getElementById('addBlock').style.display = 'none';
        document.getElementById('mask').style.display = 'none';
        return false;
    }
   
}

// 修改中的取消按钮
function addCancel() {
    // location.reload();  //实现页面重新加载
    // 关闭修改框架
    document.getElementById('addBlock').style.display = 'none';
    document.getElementById('mask').style.display = 'none';
}
